﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public DataSet QueryQPPLAN(DataRow dwData, int option = 1)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            OracleCommand or1;

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT* FROM QPPLAN"
                        + " WHERE  QPPSPGRD='  ' AND QPPPNRKRS=:QPPPNRKRS AND QPPPLFDNR=:QPPPLFDNR"
                           + " ORDER BY 1,2,3";
                    or1.Parameters.Add("QPPPNRKRS", OracleType.NVarChar).Value = dwData["QPPPNRKRS"].ToString();
                    or1.Parameters.Add("QPPPLFDNR", OracleType.NVarChar).Value = dwData["QPPPLFDNR"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT* FROM QPPLAN"
                        + " WHERE   QPPSPGRD='  ' AND QPPMANDANT=:QPPMANDANT"
                        + " ORDER BY 1,2,3";
                    or1.Parameters.Add("QPPMANDANT", OracleType.NVarChar).Value = dwData["QPPMANDANT"].ToString();
                    break;
                default:
                    or1.CommandText = "SELECT* FROM QPPLAN"
                        + " WHERE   QPPSPGRD='  ' AND QPPPNRKRS=:QPPPNRKRS AND QPPPLFDNR=:QPPPLFDNR"
                           + " ORDER BY 1,2,3";
                    or1.Parameters.Add("QPPPNRKRS", OracleType.NVarChar).Value = dwData["QPPPNRKRS"].ToString();
                    or1.Parameters.Add("QPPPLFDNR", OracleType.NVarChar).Value = dwData["QPPPLFDNR"].ToString();
                    break;
            }

            SResult = Connect2Proxy(or1);
            if (SResult.Tables.Count > 0)
            {
                SResult.Tables[0].TableName = "QPPLAN";
                SReturn.Merge(SResult);
            }

            return SReturn;
        }
    }
}
